package com.one.oa.api.controller;

import com.one.oa.api.annation.Token;
import com.one.oa.api.bo.UserBo;
import com.one.oa.api.bo.UserFindBo;
import com.one.oa.api.bo.UserNameBo;
import com.one.oa.api.bo.UserPhoneBo;
import com.one.oa.api.service.UserService;
import com.one.oa.constants.SystemConfig;
import com.one.oa.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * .           ,%%%%%%%%,
 * .         ,%%/\%%%%/\%%
 * .        ,%%%\c "" J/%%%
 * %.       %%%%/ o  o \%%%
 * `%%.     %%%%    _  |%%%
 * `%%      `%%%%(__Y__)%%'
 * //        ;%%%%`\-/%%%'
 * ((        /  `%%%%%%%'
 * \\    .'          |
 * \\  /       \  | |
 * \\/         ) | |
 * \         /_ | |__
 * (___________)))))))
 * 攻城狮 永无bug!
 *
 * @ClassName UserController
 * @Author lemon
 * @create 2023/3/25 8:54
 */
@RestController
@RequestMapping("/api/user/")
@Api(tags = "用户管理")
public class UserController {
    @Resource
    private UserService service;

    @ApiOperation(value = "校验用户名")
    @GetMapping("checkname")
    public R checkName(String name){
        return service.checkName(name);
    }

    @ApiOperation(value = "校验手机号")
    @GetMapping("checkphone")
    public R checkPhone(String phone){
        return service.checkPhone(phone);
    }

    @ApiOperation(value = "注册账号")
    @PostMapping("register")
    public R register(@RequestBody UserBo bo){
        return service.register(bo);
    }

    @ApiOperation(value = "查询全部")
    @GetMapping("all")
    public R all(){
        return service.all();
    }

    @ApiOperation(value = "账号登录")
    @PostMapping("loginname")
    public R loginName(@RequestBody UserNameBo bo){
        return service.loginName(bo);
    }

    @ApiOperation(value = "验证码登录")
    @PostMapping("logincode")
    public R loginCode(@RequestBody UserPhoneBo bo){
        return service.loginCode(bo);
    }

    @Token
    @ApiOperation(value = "退出登录")
    @GetMapping("loginout")
    public R loginOut(HttpServletRequest request){
        return service.loginOut(request.getHeader(SystemConfig.HEADER_AUTH));
    }
    @ApiOperation(value = "校验令牌")
    @GetMapping("checktoken")
    public R checkToken(HttpServletRequest request){
        return service.checkToken(request.getHeader(SystemConfig.HEADER_AUTH));
    }
    @ApiOperation(value = "密码找回")
    @PostMapping("findpass")
    public R findPass(@RequestBody UserFindBo bo){
        return service.findPass(bo);
    }

    @Token
    @ApiOperation(value = "密码修改")
    @PostMapping("updatepass")
    public R updatePass(String password,HttpServletRequest request){
        return service.updatePass(request.getHeader(SystemConfig.HEADER_AUTH),password);
    }
}
